#!/usr/bin/env ruby

require 'thor'
require_relative 'tdberlintest/version'
require_relative 'wolfram_api_fetcher'
require_relative 'stackoverflow_api_fetcher'

module TdBerlinTest
  class TestManager < Thor

    desc 'task1', 'execute task1 of test. specify input yaml file. e.g.: ruby test.rb task1 -i langs.yaml'
    long_desc <<-LONGDESC
    Query the Wolfram Alpha API and parse the output.

    The Wolfram Alpha API allows you to pass a list of programming languages.

    The result contains a table with a new set of languages which were influenced by the requested programming languages.

    ### Input

    A yaml file with the sample contents:

        ---
        - langs: [ruby, scheme, haskell]

    ### Output

    A list with languages which were all influenced by the input languages:

        ['Perl','Lisp', 'Dylan', 'Elixir', ... ]
    LONGDESC
    method_option :input, :aliases => '-i', :desc => 'Specify input yaml file', :default => 'langs.yaml'
    def task1
      wolfram_api_fetcher = TdBerlinTest::WolframApiFetcher.new options[:input]
      wolfram_api_fetcher.run
    end

    desc 'task2', 'execute task2 of test. specify input yaml file. e.g.: ruby test.rb task2 -i langs.yaml'
    long_desc <<-LONGDESC
    Query the Stackexchange API and parse the output.

    Handle the input list (programming languages as strings) as stackoverflow tags and retrieve the "stackoverflow-tag-usage-count" from the API.

    ### Input

    A yaml file with the sample contents:

        ---
        - langs: [ruby, scheme, haskell]

    ### Output

    A hash holding the programming languages as keys and the according "stackoverflow-tag-usage-count" as values, printed in order by value:

    {
        'ruby' => 10000,
        'haskell' => 5000,
        ...
    }

    LONGDESC
    method_option :input, :aliases => '-i', :desc => 'Specify input yaml file', :default => 'langs.yaml'
    def task2
      stackexchange_api_fetcher = TdBerlinTest::StackexchangeApiFetcher.new options[:input]
      stackexchange_api_fetcher.run
    end
  end
end

TdBerlinTest::TestManager.start(ARGV)